package com.qax.task.cron.support;

import java.lang.reflect.UndeclaredThrowableException;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * 父类委托处理器
 * @author leiliang
 */
public class DelegatingRunnable implements Runnable{

    private final Runnable delegate;

    private static final Logger logger = Logger.getLogger(DelegatingRunnable.class.getName());

    /**
     * Create a new DelegatingRunnable.
     * @param delegate the Runnable implementation to delegate to
     */
    public DelegatingRunnable(Runnable delegate) {
        this.delegate = delegate;
    }

    @Override
    public void run() {
        try {
            this.delegate.run();
        }
        catch (UndeclaredThrowableException ex) {
            logger.log(Level.WARNING,"server warning\t"+ ex.getMessage());
        }
        catch (Throwable ex) {
            logger.log(Level.FINE,"server error \t"+ ex.getMessage());
        }
    }

    @Override
    public String toString() {
        return "DelegatingRunnable for " + this.delegate;
    }
}
